package geektime.concurrent.race;

import java.util.Random;

public class SimpleSyncGen2 implements GenRunnable {

    SimpleShareData ssd;
    int size;
    int offset;

    public SimpleSyncGen2(SimpleShareData ssd, int size, int offset) {
        this.ssd = ssd;
        this.size = size;
        this.offset = offset;
    }

    @Override
    public void run() {
        gen();
    }

    @Override
    public void gen() {
        // System.out.println("开始产生随机数: " + size);
        Random rand = new Random(System.currentTimeMillis());
        int r;
        int i;
        synchronized (ssd.getScore()) {
            for (i = 0; i < size; i++) {
                r = rand.nextInt(SimpleShareData.COUNT);
                ssd.getScore().add(new Integer(r));
            }
        }
        // System.out.println("产生随机数个数: " + i);
        ssd.getGenSig().countDown();
    }

}
